package com.xnyzc.lhy.didi.controller.synchronization;

import com.xnyzc.lhy.common.component.didi.DiDiUrlConstant;
import com.xnyzc.lhy.common.entity.DiDiRv;
import com.xnyzc.lhy.common.entity.netty.StriveCallbackParam;
import com.xnyzc.lhy.common.exception.DiDiException;
import com.xnyzc.lhy.common.penum.EDiDiErrorCode;
import com.xnyzc.lhy.didi.entity.param.synchronization.*;
import com.xnyzc.lhy.didi.service.synchronization.DataSynchronizationCorrelationService;
import com.xnyzc.lhy.common.util.sign.AttestationTool;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单相关
 * </p>
 *
 * @author wangshuo
 * @since 2019-09-25
 */
@RestController
@RequestMapping("oa/didi/synchronization")
public class DataSynchronizationController {

    @Autowired
    private DataSynchronizationCorrelationService dataSynchronizationCorrelationService;

    /**
     * 司机位置同步
     *
     * @param locationSyncParam
     * @return
     */
    @ApiOperation(value = "司机位置同步", notes = "司机位置同步")
    @PostMapping(value = "/getLocationSync")
    public DiDiRv getLocationSync(@ApiParam(name =
            "locationSyncParam", value = "司机位置同步") @RequestBody LocationSyncParam locationSyncParam) {
        return dataSynchronizationCorrelationService.getLocationSync(locationSyncParam);
    }

    /**
     * 实时计价同步
     *
     * @param realtimeFeeSyncParam
     * @return
     */
    @ApiOperation(value = "实时计价同步", notes = "实时计价同步")
    @PostMapping(value = "/getRealtimeFeeSync")
    public DiDiRv getRealtimeFeeSync(@ApiParam(name =
            "realtimeFeeSyncParam", value = "实时计价同步") @RequestBody RealtimeFeeSyncParam realtimeFeeSyncParam) {
        return dataSynchronizationCorrelationService.getRealtimeFeeSync(realtimeFeeSyncParam);
    }

    /**
     * 司机状态同步
     *
     * @param statusCallbackParam
     * @return
     */
    @ApiOperation(value = "司机状态同步", notes = "司机状态同步")
    @PostMapping(value = "/getStatusCallback")
    public DiDiRv getStatusCallback(@ApiParam(name =
            "statusCallbackParam", value = "司机状态同步") @RequestBody StatusCallbackParam statusCallbackParam) {
        return dataSynchronizationCorrelationService.getStatusCallback(statusCallbackParam);
    }

    /**
     * 司机抢单
     *
     * @param striveCallbackParam
     * @return
     */
    @ApiOperation(value = "司机抢单", notes = "司机抢单")
    @PostMapping(value = "/getStriveCallback")
    public DiDiRv getStriveCallback(@ApiParam(name =
            "statusCallbackParam", value = "司机抢单") @RequestBody StriveCallbackParam striveCallbackParam) {
        return dataSynchronizationCorrelationService.getStriveCallback(striveCallbackParam);
    }

    /**
     * 司机抢单结果同步
     *
     * @param driverSingleSynchronousParam 参数
     * @return
     */
    @ApiOperation(value = "司机抢单结果同步", notes = "司机抢单结果同步")
    @PostMapping(value = "/driverSingleSynchronous")
    public DiDiRv driverSingleSynchronous(@ApiParam(name =
            "driverSingleSynchronousParam", value = "司机抢单结果同步") DriverSingleSynchronousParam driverSingleSynchronousParam) {
        if (!AttestationTool.getRequestSign(driverSingleSynchronousParam, driverSingleSynchronousParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return dataSynchronizationCorrelationService.driverSingleSynchronous(driverSingleSynchronousParam);
    }

    /**
     * 司机抢单结果feign调用
     * @param driverSingleSynchronousParam 参数
     */
    @PostMapping(value = "/driverSingleSynchronousFeign")
    public void  driverSingleSynchronousFeign(@RequestBody DriverSingleSynchronousParam driverSingleSynchronousParam) {
        dataSynchronizationCorrelationService.driverSingleSynchronous(driverSingleSynchronousParam);
    }

    /**
     * 司机位置批量同步
     *
     * @param multiLocationSyncParam
     * @return
     */
    @ApiOperation(value = "司机位置批量同步", notes = "司机位置批量同步")
    @PostMapping(value = "/getMultiLocationSync")
    public DiDiRv getMultiLocationSync(@ApiParam(name =
            "locationSyncParam", value = "司机位置批量同步") MultiLocationSyncParam multiLocationSyncParam) {
        return dataSynchronizationCorrelationService.getMultiLocationSync(multiLocationSyncParam);
    }

}
